/**
 * @author mamat-dev
 */

package com.googlecode.explorecode.mamat.sendimage;

import javax.microedition.lcdui.*;

class DisplayImage extends Canvas implements CommandListener {
	private final CameraMIDlet midlet;
	private Image image = null;
	private StringItem messageItem;
	private final Command exitCommand;
	private Command nextCommand = null;
	DisplayImage(CameraMIDlet midlet) {
		this.midlet = midlet;
		messageItem = new StringItem("Message", "start");
		exitCommand = new Command("EXIT", Command.EXIT, 1);
		addCommand(exitCommand);
		setCommandListener(this);
		nextCommand = new Command("CAMERA", Command.OK, 1);
		addCommand(nextCommand);
	}
	/**
	 *	Buat image dengan byte-Array
     *
	 **/
	void setImage(byte[] pngImage) {
		image = image.createImage(pngImage, 0, pngImage.length);
		repaint();
	}
	public void commandAction(Command c, Displayable d) {
		if (c == exitCommand) {
			midlet.cameraFormExit();
		} else {
			midlet.displayCanvasBack();
		}
	}
	/**
	 *	Tampilkan image
	 **/
	public void paint(Graphics g) {
		g.setColor(0x0000ffff);//cyan/biru terang
		g.fillRect(0, 0, getWidth(), getHeight());
		if (image != null) {
			g.drawImage(image, getWidth() / 2, getHeight() / 2,
					Graphics.VCENTER | Graphics.HCENTER);
		}
	}
}
